import Vue from "vue";
import Router from "vue-router";

import NProgress from "nprogress";
import "nprogress/nprogress.css";

Vue.use(Router);

// 修复重复点击路由报错
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

// export default new Router({
const router = new Router({
  mode: "history",
  base: process.env.BASE_URL,
  routes: [
    {
      path: "/",
      redirect: "/home",
    },
    // {
    // path: "/",
    // redirect: "/login",
    // },
      {
        path: "/outpage",
        name: "outPage",
        component: () => import("./layout/OutPage"),
        children: [
          {
            path: "/ScreenBasicLayout",
            // component: { render: h => h("router-view") },
            // redirect: "index",
            component: () =>
              import(
                /* webpackChunkName: "index" */
                "./layout/ScreenBasicLayout.vue"
              ),
            children: [
                {
                    path: "/home",
                    name: "home",
                    component: () => import("./views/home/index"),   
                },
                {
                    path: "/worklist",
                    name: "worklist",
                    component: () => import("./views/workList/index"),   
                },
                {
                    path: "/personal",
                    name: "personal",
                    component: () => import("./views/personal/index"),   
                },
                {
                    path: "/blogger",
                    name: "blogger",
                    component: () => import("./views/blogger/index"),   
                },
            ],
          },
        //   {
        //     path: "/home",
        //     name: "home",
        //     component: () => import("./views/home/Index"),
        //   },
        //   {
        //     path: "/login",
        //     name: "login",
        //     component: () => import("./views/login/Index"),
        //   },
        ],
      },
    // {
    // path: "/home",
    // name: "home",
    // component: () => import("./views/home/index"),   
    // },
    {
      path: "*",
      name: "404",
      component: () => import("./views/notfound/notfound"),
    },
  ],
});

router.beforeEach((to, from, next) => {
  // console.log('to',to)
  NProgress.start();
  next();
});
router.afterEach(() => {
  NProgress.done();
});
export default router;
